package warmup.main;
import warmup.model.Student;
import java.util.Scanner;

public class StudentManager {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 1. 定义一个可以存放3个学生的数组
        Student[] students = new Student[3];

        System.out.println("--- 请输入3名学生的信息 ---");

        // 2. 使用 for 循环，从控制台接收用户输入
        for (int i = 0; i < students.length; i++) {
            System.out.println("请输入第" + (i + 1) + "名学生的信息：");
            System.out.print("学号：");
            String id = scanner.nextLine();

            System.out.print("姓名：");
            String name = scanner.nextLine();

            System.out.print("年龄：");
            int age = scanner.nextInt();
            scanner.nextLine(); // 消费掉换行符

            // 创建 Student 对象并存入数组
            students[i] = new Student(id, name, age);
        }

        System.out.println("\n--- 所有学生信息如下 ---");
        // 3. 使用 for-each 循环打印学生信息
        for (Student student : students) {
            System.out.println(student);
        }

        // 4. 验证 equals 和 hashCode
        System.out.println("\n--- equals和hashCode验证 ---");
        Student s1 = new Student("2024001", "张三", 20);
        Student s2 = new Student("2024001", "张小三", 21);
        System.out.println("s1.equals(s2)的结果应该是 true：" + s1.equals(s2));
        System.out.println("s1.hashCode() == s2.hashCode()的结果应该是 true：" +
                (s1.hashCode() == s2.hashCode()));

        scanner.close();
    }
}